package zuoye08;

import java.io.*;
import java.util.ArrayList;
import java.util.Random;

public class zuoye06 {
     public static void main(String[] args) throws IOException {
         BufferedReader br = new BufferedReader(new FileReader("Mingzi.txt"));
         String student=br.readLine();
         ArrayList<String> arr=new ArrayList<>();
         while(student!=null){
             arr.add(student);
             student=br.readLine();
         }
         System.out.println(arr);
         Random rc=new Random();
         int n=0;
         int  j=0;
         if(arr.size()>1) {
             n = rc.nextInt(arr.size() - 1);
         }
         System.out.println(n);
         String str=arr.get(n);
         System.out.println(str);
         BufferedWriter bw=new BufferedWriter(new FileWriter("copyy.txt",true));
         BufferedWriter bw2=new BufferedWriter(new FileWriter("Mingzi.txt"));
             if(arr.size()==1)
             {

                 bw.write(arr.get(0));
                 bw.write("\n");
                 bw.close();
                 BufferedReader br2=new BufferedReader(new FileReader("copyy.txt"));
                 String s2=br2.readLine();
                 while (s2!=null)
                 {
                     bw2.write(s2);
                     bw2.write("\n");
                     s2=br2.readLine();
                 }

            br2.close();
                 bw2.close();
                 BufferedWriter bw3=new BufferedWriter(new FileWriter("copyy.txt"));
                 bw3.close();
             }
             else
             {
                 for(String s:arr)
                 {
                     if(!s.equals(str))
                     {
                         bw2.write(s);
                         bw2.write("\n");
                     }
                 }
                 bw.write(str);
                 bw.write("\n");
             }
         br.close();
         bw2.close();
         bw.close();
     }
}
